<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>XMLHttpRequest Basic Test</title>
    <script language="javascript">
      var xmlhttp = false;

      /*@cc_on @*/

      /*@if (@_jscript_version >= 5)
        try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
      }
      @else
        xmlhttp = false;
      @end @*/

      if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
        try {
          xmlhttp = new XMLHttpRequest();
        } catch (e) {
          xmlhttp = false;
        }
      }

      function processResponse() {
        //alert("get into processResponse ...");
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
          document.forms[0].OutputBox.value = xmlhttp.responseText;
        } else {
          document.forms[0].OutputBox.value = xmlhttp.statusText;
        }          
      }
      
      function sendRequestByGet() {
        //alert("get into sendRequestByGet ...");
        if (xmlhttp) {
          alert("prepare to send ...");
          var data = encodeURIComponent(document.getElementById("InputBox").value);
          //alert("data=" + data);
          xmlhttp.open("GET", "http://localhost:8080/examples/basic.jsp?data=" + data, true);
          xmlhttp.onreadystatechange = processResponse;
          xmlhttp.send(null);
          //alert("sent out ...");
        }
      }
      
      function sendRequestByPost() {
        var url = "http://localhost:8080/examples/basic.jsp";
        var data = encodeURIComponent(document.getElementById("InputBox").value);
        var params = "data=" + data;
        xmlhttp.open("POST", url, true);

        //Send the proper header information along with the request
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", params.length);
        xmlhttp.setRequestHeader("Connection", "close");
        
        xmlhttp.onreadystatechange = processResponse;
        xmlhttp.send(params);
      }
    </script>
    <style>
      body, td {
        font-family: Arial;
        font-size: 13px;
      }
    </style>
  </head>

  <body>
    <h1>XMLHttpRequest Basic Test</h1>
    <h4>This script uses XMLHttpRequest, Javascript and Jsp to test basic XMLHttpRequest.</h4>
    <form id="form1">
      <p><textarea cols="60" rows="8" id="InputBox">Watch me change when you press a button!</textarea></p>
      <p><textarea cols="60" rows="8" id="OutputBox"></textarea></p>
      <p><input type="button" value="Send" onClick="sendRequestByPost();"></p>
    </form>
  </body>
</html>
